/**
 * 给定排序数组nums，查找target的位置，没找到返回-1
 * @param {number[]} nums 
 * @param {number} target 
 */
var search = function (nums, target) {
    let left = 0, right = nums.length - 1
    while (left <= right) {
        // 向下取整 + 防止整数溢出
        mid = Math.floor(left + (right - left) / 2)
        if (nums[mid] === target) {
            return mid
        } else if (target < nums[mid]) {
            right = mid - 1
        } else {
            left = mid + 1
        }
    }
    return -1
}